#!/bin/sh
# filename: ddestroy
# description: delete dataset 

#     Copyright © 2012-2013 Michael Eager <michael.eager@monash.edu>, 
#     Toan Nguyen <toan.nguyen@monash.edu>
#
#     This file is part of Xglom.
# 
#     This is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
# 
#     This is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.



# check if arguments (command) are specified
if [[ $# -eq 0 ]]; then
	echo "Error: no argument is specified."
	exit 1
fi


. dcheck

P_FLAG=

until [ -z "$1" ]
do
    case "$1" in
        "-c" | "-cid" )
        ASSET_CID=$2
        shift
        ;;
        * )
        shift
        ;;
    esac
done

if [ -z $ASSET_CID ]
then {
    echo "Error: must input asset cid"
    exit 1;
}
fi

kdialog --warningyesno "Deleting dataset ${ASSET_CID} on vera059.its.monash.edu? *WARNING* pressing 'Yes' will permenently destroy the data on the DaRIS server. Do you wish to delete the dataset?";

if [ "$?" = 0 ]; then
	echo "YOU CHOSE YES";
	$MFCOMMAND om.pssd.object.destroy :id "${ASSET_CID}"

elif [ "$?" = 1 ]; then
	echo "YOU CHOSE not to delete dataset.";
else
	echo "ERROR in ddestroy, kdialog command.";
fi;



